package com.goblin.model.order.po;

import com.goblin.model.base.BaseEntity;
import com.goblin.model.uaa.po.CustomerUser;
import lombok.Data;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Data
@Table(name = "t_order_info")
@Entity
public class Order extends BaseEntity {

    @Column(name = "orderCode", columnDefinition = "varchar(255) COMMENT '订单编号'")
    private String orderCode;

    @Column(name = "item_count", columnDefinition = "int(2) COMMENT '商品种类数量'")
    private Integer itemCount;

    @Column(name = "place_date", columnDefinition = "datetime COMMENT '下单时间'")
    private Date placeDate;

    @Column(name = "pay_type", columnDefinition = "varchar(4) COMMENT '支付渠道'")
    private String payType;

    @Column(name = "pay_date", columnDefinition = "datetime COMMENT '支付时间'")
    private Date payDate;

    @Column(name = "out_trade_no", columnDefinition = "varchar(255) COMMENT '三方支付流水号'")
    private String outTradeNo;

    @Column(name = "delivery_type", columnDefinition = "varchar(4) COMMENT '配送方式'")
    private String deliveryType;

    @Column(name = "sum_price", columnDefinition = "double(10,2) COMMENT '商品总金额'")
    private Double sumPrice;

    @Column(name = "freight", columnDefinition = "double(10,2) COMMENT '运费'")
    private Double freight;

    @Column(name = "pay_price", columnDefinition = "double(10,2) COMMENT '实际支付金额'")
    private Double payPrice;

    @Column(name = "status", columnDefinition = "varchar(4) COMMENT '订单状态'")
    private String status;

    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "store_id", referencedColumnName = "id", nullable = false, columnDefinition = " int(11) COMMENT '商铺id'")
    private Store store;

    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "sku_id", referencedColumnName = "id", nullable = false, columnDefinition = " int(11) COMMENT 'sku id'")
    private SKU sku;

    @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinTable(name = "t_order_combine_product", joinColumns = @JoinColumn(name = "order_product_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "order_id", referencedColumnName = "id"), foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT))
    private List<OrderProduct> orderProducts;

    @OneToOne(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = false, columnDefinition = " int(11) COMMENT '创建人id'")
    private CustomerUser customerUser;
}
